{% extends "personal_center/base.html" %}

{% block page_link %}
{#    <link href="../../static/orderscreate/css/bootstrap.min.css" rel="stylesheet">#}
    <link href="../../static/orderscreate/css/fileinput.min.css" rel="stylesheet">
    <link href="../../static/orderscreate/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../../static/orderscreate/css/font-awesome.4.6.0.css">
    <link href="../../static/orderscreate/form_builder/animate.min.css" rel="stylesheet">
    <link href="../../static/orderscreate/form_builder/summernote.css" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="../../static/jqueryjsPlumb/css/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../../static/jqueryjsPlumb/css/style.css">

    <link href="../../static/orderscreate/form_builder/style.min862f.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../../static/orderscreate/css/index.css">
    <script src="../../static/system_setup/creat_from/js/jquery-1.10.2.js"></script>
{#    <script src="../../static/orderscreate/javascript/bootstrap.min.js"></script>#}
    <script src="../../static/orderscreate/javascript/fileinput.min.js"></script>
    <script src="../../static/orderscreate/javascript/bootstrap-datetimepicker.min.js"></script>
    <script src="../../static/orderscreate/javascript/distpicker.data.min.js"></script>
    <script src="../../static/orderscreate/javascript/distpicker.min.js"></script>
    <script src="../../static/orderscreate/javascript/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../../static/orderscreate/javascript/zh.js"></script>
    <script src="../../static/orderscreate/javascript/jquery-ui.min.js"></script>
    <script src="../../static/orderscreate/form_builder/beautifyhtml.js"></script>
    <script src="../../static/orderscreate/javascript/index.js"></script>
    <link rel="stylesheet" href="../../static/technological/css/style.css">
    <link rel="stylesheet" type="text/css" href="../../static/finance/css/custom.css">
    <script type="text/javascript" src="../../static/public_file/js/ModalBox1.js"></script>
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline" style="border-bottom: #cfcfcf solid 0.5px;">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
        </div>
{#        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">#}
{#            <button id="add_station" type="button"#}
{#                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"#}
{#                    onclick="save_data()">#}
{#                保存#}
{#            </button>#}
{#        </div>#}

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="submit_data()">
                提交
            </button>
        </div>
    </div>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from" style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            {% autoescape off %}{{ data.business_html }}{% endautoescape %}
        </div>

    </div>

    <div id="new_models" style="width: 100%;height: 94%;position: absolute;display: none;background-color: rgba(36, 36, 36, 0.1);z-index: 10000;">
        <div id="box" style="width: 700px;height: 500px;background: white;z-index: 10100;position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #cfcfcf solid 1px;">
            <div style="width: 100%;height: 50px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #8c939d solid 1px;">
                <h5 id="model_title" class="modal-title"
                    style="line-height: 50px;width: 15%;margin-left: 1%;display: inline-block;"></h5>
                <button id="close-model" type="button" class="close" data-dismiss="modal" aria-label="Close"
                        style="margin-right: 3%;line-height: 50px;">
                    <span onclick="close_models()" aria-hidden="true" style="font-size: 28px;">×</span>
                </button>
            </div>
            <div style="height: 400px;width: 100%;padding-top: 2%;padding-left: 2%;border-bottom: #cfcfcf solid 1px;">
                <div style="display: inline-block;width: 30%;height: 100%;border-right: #E8E8E8 solid 1px;">
                    <div style="width: 100%;height: 35px;color: #0b0b0b;text-align: center;">
                        <div class="search1" style="vertical-align: center;">
                            <input type="text" placeholder="请输入..." name="" id="search_data" value="">
                            <button id="search_button">搜索</button>
                        </div>
                    </div>
                    <div style="width: 100%;height: 35px;line-height: 35px;padding-left: 2%;color: #0b0b0b;border-bottom: #cfcfcf solid 1px;">
                        <div id="an_branch"
                             style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;color: #01aaed;">
                            按部门
                        </div>
                        <div id="an_role"
                             style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;">按角色
                        </div>
                        <div id="an_staff"
                             style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;">按人员
                        </div>
                    </div>
                    <div id="department_list" style="width: 100%;height: 315px;overflow: auto;">
                        <div style="width: 100%;height: 100%;text-align: center;">
                            <img style="width: 30%;height: 30%;margin-top: 35%;"
                                 src="../../static/public_file/images/jiazai.gif" alt="">
                        </div>
                    </div>
                </div>

                <div id="right_role_li"
                     style="display: none;width: 69%;height: 100%;overflow: auto;vertical-align: top;left: 0;">

                    <table class="table table-hover table-bordered"
                           style="border-collapse: collapse;margin: 0;padding: 0;">

                        <thead>
                        <tr>
                            <th scope="col" style="width: 10%;">
                                <input id="all_select_checkbox" type="checkbox">
                            </th>
                            <th scope="col" style="width: 20%;">序号</th>
                            <th scope="col" style="width: 35%;">姓名</th>
                            <th scope="col" style="width: 35%;">工号</th>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="t_table2"></tbody>
                    </table>
                    <div id="img-display1" style="width: 75%;text-align: center;">
                        <div style="margin-top: 10%;">
                            <img src="../../static/public_file/images/page-img/11.jpg" alt="">
                            <p style="margin: 0;padding: 0;vertical-align: top;">暂无数据</p>
                        </div>
                    </div>
                </div>

                <div style="height: 30%;width: 100%;border-top: #E8E8E8 solid 1px;overflow: auto;display: none;">
                    <div id="checked-label" style="margin-top: 1%;margin-left: 3%;width: 90%;">

                    </div>
                </div>
            </div>
            <div style="width: 100%;height: 50px;text-align: right;padding-right: 2%;">
                <button id="model-affirm"
                        style="width: 100px;height: 36px;border: #dfdfdf solid 1px;margin-top: 7px;border-radius: 3px;">确认
                </button>
            </div>
        </div>
    </div>

    <div id="new_models2" style="width: 100%;height: 100%;position: absolute;display: none;background-color: rgba(36, 36, 36, 0.1);z-index: 11000;top: 0;left: 0;">
        <div id="box2" style="width: 700px;height: 500px;background: white;z-index: 10100;position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #cfcfcf solid 1px;">
            <div id="title2" style="width: 100%;height: 50px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #8c939d solid 1px;">
                <h5 id="model_title2" class="modal-title" style="line-height: 50px;width: 15%;margin-left: 1%;display: inline-block;">选择科室</h5>

                <span onclick="close_models2()" style="float: right;padding-right: 2%;cursor: pointer;line-height: 50px;">
                    <i class="iconfont icon-quchu"></i>
                </span>
            </div>
            <div style="height: 400px;width: 100%;padding-top: 2%;padding-left: 2%;border-bottom: #cfcfcf solid 1px;overflow: auto;">
                {% for company in company_list %}
                    <div style="display: inline-block;width: 300px;height: 30px;line-height: 30px;font-size: 14px;color: #0b0b0b;">
                        <input class="check_box3" id="{{ company.name }}({{ company.id }})" type="checkbox"> {{ company.name }}
                    </div>
                {% endfor %}
            </div>
            <div style="width: 100%;height: 50px;text-align: right;padding-right: 2%;">
                <button onclick="choose_department()" id="model-affirm2" style="width: 100px;height: 36px;border: #dfdfdf solid 1px;margin-top: 7px;border-radius: 3px;cursor: pointer;">确认
                </button>
            </div>
        </div>
    </div>

    <div id="addForm">
        <div id="title3">
            <div style="height: 50px;width: 20%;margin-left: 1%;display: inline-block;line-height: 50px;font-size: 20px;">
                选择审批人员
            </div>

            <div class="search3" style="vertical-align: center;display: inline-block;text-align: right;margin-left: 35%;font-size: 14px;">
                <input type="text" placeholder="请输入..." name="" id="search_data2" value="">
                <button id="search_button2">搜索</button>
            </div>
            <span onclick="close_models3()" style="float: right;line-height: 50px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
        </div>
        <hr>
        <div style="display: inline-block;width: 30%;height: 350px;border-right: #E8E8E8 solid 1px;">
            <div style="width: 100%;height: 35px;line-height: 35px;padding-left: 2%;color: #0b0b0b;border-bottom: #cfcfcf solid 1px;font-size: 14px;">
                <div id="an_branch1"
                     style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;color: #01aaed;">
                    按部门
                </div>
                <div id="an_rank1"
                     style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;">按权限
                </div>
                <div id="an_func1"
                     style="width: 31.5%;display: inline-block;cursor: pointer;text-align: center;">按职能
                </div>
            </div>
            <div id="department_list1" style="width: 100%;height: 315px;overflow: auto;">
                <div style="width: 100%;height: 100%;text-align: center;">
                    <img style="width: 30%;height: 30%;margin-top: 35%;"
                         src="../../static/public_file/images/jiazai.gif" alt="">
                </div>
            </div>
        </div>

        <div style="display: inline-block;width: 69.5%;height: 350px;overflow: auto;vertical-align: top;left: 0;font-size: 14px;">
            <table class="table table-hover table-bordered" style="border-collapse: collapse;margin: 0;padding: 0;width: 100%;">
                <thead style="width: 100%;">
                    <tr style="width: 100%;">
                        <th scope="col" style="width: 10%;height: 30px;border: #dfdfdf solid 1px;">
                            <input id="all_select_checkbox2" type="checkbox">
                        </th>
                        <th scope="col" style="width: 20%;height: 30px;border: #dfdfdf solid 1px;">序号</th>
                        <th scope="col" style="width: 35%;height: 30px;border: #dfdfdf solid 1px;">姓名</th>
                        <th scope="col" style="width: 35%;height: 30px;border: #dfdfdf solid 1px;">工号</th>
                    </tr>
                </thead>
                <tbody style="overflow: auto;" id="t_table3"></tbody>
            </table>
            <div id="img-display2" style="width: 75%;text-align: center;">
                <div style="margin-top: 10%;">
                    <img src="../../static/public_file/images/page-img/11.jpg" alt="">
                    <p style="margin: 0;padding: 0;vertical-align: top;">暂无数据</p>
                </div>
            </div>
        </div>

        <div style="height: 150px;width: 100%;border-top: #E8E8E8 solid 1px;overflow: auto;">
            <div id="checked-label2" style="margin-top: 1%;margin-left: 3%;width: 90%;font-size: 14px;">

            </div>
        </div>
        <hr>
        <div style="height: 70px;padding-right: 2%;font-size: 14px;">
            <button onclick="choose_people()" id="model-affirm1" style="border-radius: 3px;height: 30px;float: right;margin-top: 15px;border: #1E90FF solid 1px;background: #1E90FF;color: white;">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;提&nbsp;交&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </button>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script src="../../static/jqueryjsPlumb/js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="../../static/jqueryjsPlumb/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../static/jqueryjsPlumb/js/jquery.jsPlumb.min.js"></script>
    <script type="text/javascript" src="../../static/jqueryjsPlumb/js/index.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->
    <script type="text/javascript" src="../../static/finance/js/custom.js"></script>

    <script type="text/javascript">
        window.onload = function () {
            document.getElementsByClassName("right_body")[0].style.width = "85.5%";
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
            if (document.getElementById("real_name")) {
                document.getElementById("real_name").innerText='{{ realname }}';
            }
            if (document.getElementById("department")) {
                document.getElementById("department").innerText='{{ department }}';
            }
            var label_title1_list = document.getElementsByClassName('label_title1');
            for (var tit1=0; tit1<label_title1_list.length; tit1++) {
                label_title1_list[tit1].contentEditable = false;
            }

            var label_title_list = document.getElementsByClassName('label_title');
            for (var tit=0; tit<label_title_list.length; tit++) {
                label_title_list[tit].contentEditable = false;
            }

            var label_value_list = document.getElementsByClassName('label_value');
            for (var val=0; val<label_value_list.length; val++) {
                if (label_value_list[val] !== '')
                label_value_list[val].contentEditable = true;
            }

            var checkbox_list = document.getElementsByName("choose_checkbox");
            for (var box=0; box<checkbox_list.length; box++) {
                checkbox_list[box].contentEditable = false;
            }
        };

        var uuid = '{{ uuid | safe }}';

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'zdy')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td3);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td3);tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        // 获取申请页数据
        function submit_data() {
            var form = new FormData();
            var form_code = document.getElementById('menu_from').innerHTML;
            var encode = encodeURI(form_code);            // 对字符串进行编码
            var base64_str = btoa(encode);                  // 对编码的字符串转化base64
            var CheckList = [];
            var checkbox_list = document.getElementsByName("choose_checkbox");
            for (var box=0; box<checkbox_list.length; box++) {
                var childElements = checkbox_list[box].querySelectorAll('input[type="checkbox"]');
                var child_list = [];
                for (var child=0; child<childElements.length; child++) {
                    if (childElements[child].checked) {
                        child_list.push(childElements[child].value)
                    }
                }
                CheckList.push(child_list)
            }
            form.append("data_html", base64_str);
            form.append('customer_form_id', '{{ flow_id }}');
            form.append('fj_number', uuid);
            form.append('CheckList', JSON.stringify(CheckList));
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/system-setup/low_code_bill_view", true);
            {#xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');#}
            xhr.send(form)
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        alert("提交成功！")
                        window.location = "/personal-center/CustomList.html?id={{ flow_id }}";
                    }
                }
             }
        }

        var label_count = document.getElementsByClassName('label_value label_time').length+1;
        for (var ti=1; ti<label_count; ti++){
            lay('#version').html('-v' + laydate.v);

            //执行一个laydate实例
            laydate.render({
                elem: '#time_'+String(ti), //指定元素
                type: 'date',
                format: 'yyyy-MM-dd'
            });
        }

        function choose_this(ele) {
            if (ele.checked) {
                ele.setAttribute('checked', 'true')
            } else {
                ele.setAttribute('checked', 'false')
            }
        }
    </script>
{% endblock %}



